package wpwork.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import wpwork.base.ActionResult;
import wpwork.entity.AppVersionEntity;
import wpwork.service.AppVersionService;

@RestController
@Tag(name = "示例接口", description = "appVersion")
@RequestMapping("/api/app")
public class AppVersionController {
    @Autowired
    private AppVersionService appVersionService;

    @GetMapping("/Version")
    public ActionResult getInfo() {
        AppVersionEntity info = appVersionService.getInfo();
        return ActionResult.success(info);
    }

    @PostMapping("/upload")
    public ResponseEntity<?> uploadFile(
            @RequestParam("file") MultipartFile file,
            @RequestParam(value = "version", required = false) String version,
            @RequestParam(value = "description", required = false) String description,
            @RequestParam(value = "downloadUrl", required = false) String downloadUrl) {

        try {
            AppVersionEntity result = appVersionService.uploadFile(file, version, description, downloadUrl);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("文件上传失败: " + e.getMessage());
        }
    }




}
